package com.geeklan.base.widget;

import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;

import com.smart.base.R;
import com.smart.base.databinding.LayoutLoadDialodBinding;


public class MyProgressDialog extends Dialog {
    private LayoutLoadDialodBinding layoutLoadDialodBinding;
    public MyProgressDialog(Context context) {
        super(context, R.style.TransparentDialogTheme);
        init();
    }

    public void setLoadingTest(int text){
        layoutLoadDialodBinding.tvLoadingText.setVisibility(View.VISIBLE);
        layoutLoadDialodBinding.tvLoadingText.setText(text);
    }

    public void setLoadingTest(String text){
        layoutLoadDialodBinding.tvLoadingText.setVisibility(View.VISIBLE);
        layoutLoadDialodBinding.tvLoadingText.setText(text);
    }

    private void init() {
        layoutLoadDialodBinding = LayoutLoadDialodBinding.inflate(getLayoutInflater());
        setContentView(layoutLoadDialodBinding.getRoot());
        setCancelable(false);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);

        startAnimator(layoutLoadDialodBinding.ivLoading);
    }

    private void startAnimator(View view){
        // 创建一个旋转动画
        ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(view, "rotation", 0f, 360f);
        rotationAnimator.setDuration(2000); // 动画持续时间，单位毫秒
        rotationAnimator.setInterpolator(new LinearInterpolator()); // 设置线性插值器
        rotationAnimator.setRepeatCount(ObjectAnimator.INFINITE); // 无限循环
        rotationAnimator.start();
    }
}